﻿using Jay.Sc2.Bof.Lib.State;

namespace Jay.Sc2.Bof.Lib.Action
{
	public abstract class ActionProduce : Action
	{

		private int m_BuildTime;
		private int m_Minerals;
		private int m_Gas;
		private int m_Food;

		public ActionProduce(int buildTime, int minerals, int gas, int food)
		{
			m_BuildTime = buildTime;
			m_Minerals = minerals;
			m_Gas = gas;
			m_Food = food;
		}

		public int BuildTime { get { return m_BuildTime; } }
		public int Minerals { get { return m_Minerals; } }
		public int Gas { get { return m_Gas; } }
		public int Food { get { return m_Food; } }

		public override bool IsInvalid(IBuildOrder bo)
		{
			if (bo.State.Minerals < Minerals && bo.State.WorkersOnMinerals == 0) return true;
			if (bo.State.Gas < Gas && bo.State.WorkersOnGas == 0) return true;
			if (!bo.State.HaveSupply(Food) && bo.State.SupplyBuilding == 0) return true;
			return false;
		}

		public override bool HaveResources(IBuildOrder bo)
		{
			return
				AvailableProducer(bo) > 0 &&
				bo.State.Minerals >= Minerals &&
				bo.State.Gas >= Gas &&
				bo.State.HaveSupply(Food);
		}

		public override void Execute(IBuildOrder bo)
		{
			bo.State.Minerals -= Minerals;
			bo.State.Gas -= Gas;
			bo.State.Food += Food;
		}

		public abstract int AvailableProducer(IBuildOrder bo);
	}
}
